<?php
load_file('power_group_class',LIB_PATH);
$power_group = new PowerGroup($db);

$id = intval($_POST['id']) ? intval($_POST['id']) : intval($_GET['id']);

switch($cf_action){
	case "index":
		$smarty->mypage($cf_controller,$cf_action,0) ;
		load_file('page_class',LIB_PATH);

		$MyPage = new Mypage($db);
		$data = $MyPage->from_sql('*','sys_power',"1","power_id DESC",intval($_GET['cpage']),20);
		$page = $MyPage->get_page($data,$cf_self_path.'-act_index.htm');
		$data_ary = $power_group->get_power_tree();
    break;
	
	case "add":
		if($cf_ispost){
			$power_title = $_POST['power_title'];
			$power_controller = $_POST['power_controller'];
			$power_action = $_POST['power_action'];
			$data = array(
				'power_title'=>$power_title,
				'power_controller'=>$power_controller,
				'power_action'=>$power_action
			);
			$result = $power_group->insert_power($data);
			if($result)
			my_jump('添加成功','',$cf_self_page,2);
			else
			my_jump('添加失败');
		
		}else{
			$smarty->mypage($cf_controller,$cf_action,0) ;
		}
    break;
	
	case "edit":
		if($cf_ispost){
			$power_title = $_POST['power_title'];
			$power_controller = $_POST['power_controller'];
			$power_action = $_POST['power_action'];
			$data = array(	
				'power_title'=>$power_title,
				'power_controller'=>$power_controller,
				'power_action'=>$power_action
			);
			$result = $power_group->update_power($data,"power_id='".$id."'");
			if($result)
			my_jump('修改成功','',$cf_self_page,2);
			else
			my_jump('修改失败');
		
		}else{
			$smarty->mypage($cf_controller,$cf_action,0) ;
			$row = $power_group->get_power_row($id);
                        $_SESSION['pre_url']  = $cf_pre_page ? $cf_pre_page  : ''; 
		}
    break;
	
	case "del":
		$result = $power_group->del_power("power_id='$id'");
		if($result)
			my_jump('删除成功','',$cf_self_page,2);
		else
			my_jump('删除失败');
	break;
	case "all":
		$alltype = $_POST['alltype'];
		$idlist = $_POST['idlist'];
		if($idlist){
			$list = implode(",",$idlist);
			switch($alltype){
				case "alldel":
					$result = $power_group->del_power("power_id in (".$list.")");
				break;
				default:
					my_jump('请指定操作方式');
				break;
			}	
                         
			if($result){
                            $return_page = $_SESSION['pre_url'] ? $_SESSION['pre_url'] : $cf_self_page;
                            unset($_SESSION['pre_url']);
                            my_jump('更新完成','',$return_page,1);
                        }else{
                            my_jump('更新失败');
                        }
			
		}else{
			my_jump('输入的参数有误');	
		}
	break;
	default:
		my_jump('非法操作!');
	break;
}

$smarty->assign(array(
	'id'=>$id,
	'rid'=>$rid,
	'row'=>htmlchar($row),
	'data'=>$data,
	'powerlist'=>$powerlist,
	'data_ary'=>$data_ary,
	'page'=>$page,

));
$smarty->mydisplay();

?>